import 'package:flutter/material.dart';
import 'package:im_flutter_sdk/im_flutter_sdk.dart';
import 'package:im_flutter_sdk_example/jsonserialize/im/contact.dart';
import 'package:im_flutter_sdk_example/utils/global.dart';

/*
 *@功能: 环信 聊天数据管理
 *@author: lovecrosszhu
 *@date: 2021-02-03 11:13:30
 *@version: V1.0.0
*/

class EasyMobProvider with ChangeNotifier {
  List<EMConversation> _allConversations = [];

  get conversations => _allConversations;

  Contact _contact;
  Contact get contact => _contact;

  void reqContacts() async {
    var result = await G.req.im.contactList();
    print("#####result: $result");
    ContactData contactData = ContactData.fromJson(result.data);
    if (contactData.status == 1) {
      print("contactData: ${contactData.contacts}");
      _contact = contactData.contacts[0];
    }
  }

  /// 初始化
  loadConversations() async {
    _allConversations = await EMChatManager().loadAllConversations();
    notifyListeners();
  }
}
